/*!
 * Ext JS Library 4.0
 * Copyright(c) 2006-2011 Sencha Inc.
 * licensing@sencha.com
 * http://www.sencha.com/license
 */
Ext.define('MyDesktop.view.AddBundle', {
    extend: 'Ext.ux.desktop.Module',

    requires: [
        'Ext.grid.Panel',
        'Ext.grid.RowNumberer'
    ],

    id:'add-bundle-win',

    init : function(){
        this.launcher = {
            text: 'Add Bundle Window',
            iconCls:'icon-grid'
        };
    },

    createWindow : function(){
        var me=this.app;
        var desktop = me.getDesktop();
        var win = desktop.getWindow('add-bundle-win');
        if(!win){
            win = Ext.create('Ext.window.Window',{
                title:'Add Bundle Window',
                id:'add-bundle-win',
                width: 600,
                height: 200,
                modal :true,
                layout:'fit',
                items:[{
                    layout: 'form',
                    xtype: 'form',
                    url: 'data/bundles.json',
                    bodyPadding: 5,
                    items: [{
                       fieldLabel: 'Bundle',
                       name: 'first',
                       allowBlank:false,
                       xtype:'filefield'
                    }],
                    buttons: [{
                        text: 'Upload',
                        handler: function() {
                            var form = this.up( 'form' ).getForm();
                            if(form.isValid()){
                                form.submit({
                                    url: 'data/fileupload.html',
                                    waitMsg: 'Uploading your bundle...',
                                    success: function(fp, o) {
                                        Ext.Msg.alert('Success', 'Your bundle has been uploaded.',function(){
                                            win.hide();
                                            Ext.getCmp('bundle-list-grid').getStore().load();
                                        });
                                        
                                    },
                                    failure: function(form, action) {
                                        Ext.Msg.alert('Failed',"ff",function(){
                                            win.hide();
                                            Ext.getCmp('bundle-list-grid').getStore().load();
                                        });
                                        
                                    }
                                });
                            }
                        }
                    }]
                }]
            });
        }
        return win;
    }
});

